class Student:
    def __init__(self, name, score):
        self.name = name
        self.score = score

    def __repr__(self):
        return f"Student(name='{self.name}', score={self.score})"


    def __lt__(self, other):
        return self.score < other.score


def bubble_sort_students(students):
    """
    对学生对象列表按成绩进行冒泡排序（升序）
    :param students: 学生对象列表
    :return: 排序后的列表
    """
    n = len(students)
    for i in range(n):
        swapped =False
        for j in range(0, n-i-1):

            if students[j].score > students[j+1].score:

                students[j], students[j+1] = students[j+1], students[j]

                students[j], students[j+1] = students[j+1], students[j]
                swapped = True
        if not swapped:
            break
    return students

def selection_sort_students(students):
    """"
    对学生对象列表按成绩进行排序（升序）
    :param students: 学生对象列表
    :return: 排序后的列表
    """
    n = len(students)
    for i in range(n):

        min_idx = i
        for j in range(i+1, n):
            if students[j].score < students[min_idx].score:
                min_idx = j

        students[i], students[min_idx] = students[min_idx], students[i]
    return students



def selection_sort_student(students):
    """
    对学生对象列表按成绩进行选择排序（升序）
    :param students: 学生对象列表
    :return: 排序后的列表
    """
    n = len(students)
    for i in range(n):

        min_idx = i
        for j in range(i+1, n):
            if students[j].score < students[min_idx].score:
                min_idx = j
        students[i], students[min_idx] = students[min_idx].students[i]
    return students




def selection_sort_students(students):
    """
    对学生对象列表按成绩进行排序（升序）
    :param students: 学生对象列表
    :return: 排序后的列表
    """
    n = len(students)
    for i in range(n):

        min_idx = i
        for j in range(i+1, n):
            if students[j].score < students[min_idx].score:
                min_idx = j
        students[i], students[min_idx] = students[min_idx], students[i]
    return students

def quick_sort_students(students):
    """
    对学生对象列表按成绩进行快速排序（升序）
    :param students: 学生对象列表
    :return: 排序后的列表
    """
    if len(students)  <= 1:
        return students


    pivot = students[len(students) // 2]
    left = [s for s in students if s.score < pivot.score]
    middle = [s for s in students if s.score == pivot.score]
    right = [s for s in students if s.score > pivot.score]

    return quick_sort_students(left) + middle + quick_sort_students(right)
students = [
    Student("张三",85),
    Student("李四",92),
    Student("王五",78),
    Student("赵六",90),
    Student("钱七",85),
    Student("孙八",88),
]


print("原始学生列表：")
for student in students:
    print(student)



print("\n冒泡排序结果:")
selection_sorted = selection_sort_students(students.copy())
for student in selection_sorted:
    print(student)






print("\n快速排序结果:")
quick_sorted = quick_sort_students(students.copy())
for student in quick_sorted:
    print(student)



print("\n内置sorted排序结果:")
builtin_sorted = sorted(students, key=lambda x: x.score)
for student in builtin_sorted:
    print(student)



































